import os
from multiprocessing import Process
# 现在比较少用


class MyProcess(Process):
    def __init__(self, target, name, *args, **kwargs):
        # 父类初始化
        super(MyProcess, self).__init__(target=target, args=args, kwargs=kwargs)
        # 自定义参数
        self.name = name

    def run(self):
        """
        run必须有，但是run中的代码可以根据自己的需要来编写
        :return:
        """
        print(os.getpid())
        print(f"{self.name}子进程运行了")
        super().run()


def func():
    print("子进程的代码")


if __name__ == "__main__":
    p1 = MyProcess(target=func, name="1号")
    p2 = MyProcess(target=func, name="2号")
    p3 = MyProcess(target=func, name="3号")

    p1.start()
    p2.start()
    p3.start()
